import axios from 'axios'
//引入进度条nprogress
import nprogress from "nprogress"
//引入进度条样式
import "nprogress/nprogress.css"
//引入uuid存放的那个仓库
import store from "@/store"

//创建一个axios对象
const request=axios.create({
  baseURL:'api',
  timeout:5000
})

//设置请求拦截器
request.interceptors.request.use((config)=>{
  if(store.state.detail.uuidToken){
    config.headers.userTempId = store.state.detail.uuidToken
  }
  if(store.state.user.token){
    config.headers.token = store.state.user.token
  }
  //进度条开始
  nprogress.start()
  return config
})

//设置响应拦截器
request.interceptors.response.use((res)=>{
  nprogress.done()
  return res.data
},(err)=>{
  return Promise.reject(err)
})

//导出封装好的axios
export default request